<!-- 巡检标准 -->
<template>
	<div class="zs-table-page-container">
		<!-- 查询条件 -->
		<div class="zs-card-sm zs-space-bottom zs-layout-flex-row zs-layout-justify-between">
			<span>
				<el-input v-model="queryParams.maintenanceCode" class="zs-select-md zs-space-right-sm" clearable placeholder="标准编号" />
				<el-input v-model="queryParams.maintenanceName" class="zs-select-md zs-space-right-sm" clearable placeholder="标准名称" />
				<el-select placeholder="生效状态" v-model="queryParams.effectiveState" class="zs-select-md zs-space-right-sm" @change="queryList" :teleported="false">
					<el-option v-for="item in dictObj.VALIDATE_FLAG" :key="item.dictValue" :label="item.dictLabel" :value="item.dictValue" />
				</el-select>
				<el-button class="zs-btn-plain" @click="queryList"> 查询 </el-button>
			</span>
			<span>
				<el-button class="zs-btn-md zs-btn-primary" @click="openDrawer(false, 'add', {}, 'base')" v-btnPermi="{ permis: ['p_btn_property_maintenance_standard_list_add'] }">新增</el-button>
			</span>
		</div>

		<!-- teble -->
		<div class="zs-card zs-table-page-content">
			<el-table class="zs-table-page-main" :data="tableData.data" v-loading="tableData.loading" stripe>
				<el-table-column type="index" label="序号" width="60" align="center" :index="index => index + 1 + (tableData.currentPage - 1) * curPageSize" />
				<el-table-column prop="maintenanceCode" label="标准编号" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column prop="maintenanceName" label="标准名称" show-overflow-tooltip align="left" :formatter="defaultTableData" />
				<el-table-column prop="maintenanceNum" label="标准个数" show-overflow-tooltip align="right" :formatter="defaultTableData" width="120" />
				<el-table-column label="生效状态" align="center">
					<template #default="{ row }">
						<span :class="row.effectiveState == 1 ? 'zs-validata-status-yes' : 'zs-validata-status-no'">{{ row.effectiveState == 1 ? '有效' : '失效' }}</span>
					</template>
				</el-table-column>
				<el-table-column label="审核状态" align="center">
					<template #default="{ row }">
						<span :class="row.auditStatus == 1 ? 'zs-validata-status-yes' : 'zs-validata-status-no'">{{ row.auditStatus == 1 ? '通过' : '驳回' }}</span>
					</template>
				</el-table-column>
				<el-table-column prop="" label="定义" align="center" width="120">
					<template #default="{ row }">
						<el-button class="zs-link" link size="small" @click="openDrawer(true, 'info', row, 'base')" v-btnPermi="{ permis: ['p_btn_property_maintenance_standard_list_view'] }">查看</el-button>
						<el-divider direction="vertical" />
						<el-button class="zs-link" link size="small" @click="openDrawer(false, 'edit', row, 'base')" v-btnPermi="{ permis: ['p_btn_property_maintenance_standard_list_edit'] }">编辑</el-button>
					</template>
				</el-table-column>
				<el-table-column prop="" label="标准" align="center" width="120">
					<template #default="{ row }">
						<el-button class="zs-link" link size="small" @click="openDrawer(true, 'info', row, 'config')" v-btnPermi="{ permis: ['p_btn_property_maintenance_standard_list_config_view'] }">查看</el-button>
						<el-divider direction="vertical" />
						<el-button class="zs-link" link size="small" @click="openDrawer(false, 'edit', row, 'config')" v-btnPermi="{ permis: ['p_btn_property_maintenance_standard_list_config_save'] }">配置</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="zs-space-top-sm zs-table-page-pagination">
				<el-pagination v-model:currentPage="tableData.currentPage" v-model:page-size="curPageSize" :page-sizes="curPageSizes" :small="true" :background="true" layout="total, sizes, prev, pager, next, jumper" :total="tableData.total" @size-change="pageChange('size', $event)" @current-change="pageChange('page', $event)" />
			</div>
		</div>
	</div>

	<!-- 标准信息 -->
	<DrawerStandard :isShow="drawer.base.isShowDrawer" :isReadOnly="drawer.base.isReadOnly" :handleType="drawer.base.handleType" :currentRow="currentRow.data" @close="closeDrawer($event, 'base')"> </DrawerStandard>

	<!-- 标准配置 -->
	<DrawerStandardConfig :isShow="drawer.config.isShowDrawer" :isReadOnly="drawer.config.isReadOnly" :handleType="drawer.config.handleType" :currentRow="currentRow.data" @close="closeDrawer($event, 'config')"> </DrawerStandardConfig>
</template>

<script setup>
	import DrawerStandard from './components/drawerStandard.vue';
	import DrawerStandardConfig from './components/drawerStandardConfig.vue';
	import { standardMaintainListApi } from '@/api/equipment.js';
	import { ref, reactive } from 'vue';
	import { useStore } from 'vuex';
	import { useRoute } from 'vue-router';
	import { defaultTableData } from '@/utils/publicUtils';

	const route = useRoute();
	let store = useStore();
	const curPageSizes = ref(store.state.uiPageSizes);
	const curPageSize = ref(store.state.uiPageSizeDefault);
	let dictObj = store.getters.getDictObj(['VALIDATE_FLAG', 'BUILDING_LEVEL']);

	// 列表 filed
	let tableData = reactive({
		currentPage: 1,
		total: 0,
		loading: false,
		data: [],
	});

	//查询条件
	let queryParams = reactive({ pageNumber: 1, pageSize: curPageSize.value, effectiveState: '1' });

	// 抽屉相关
	let currentRow = reactive({ data: {} });
	let drawer = reactive({
		base: {
			handleType: '',
			isReadOnly: false,
			isShowDrawer: false,
		},
		config: {
			handleType: '',
			isReadOnly: false,
			isShowDrawer: false,
		},
	});

	const openDrawer = (flag, handleType, row, drawerType) => {
		drawer[drawerType].isReadOnly = flag;
		drawer[drawerType].isShowDrawer = true;
		drawer[drawerType].handleType = handleType;
		currentRow.data = row;
	};

	const closeDrawer = (data, drawerType) => {
		drawer[drawerType].isShowDrawer = data.isShow;
		data.isRefresh && queryList();
	};

	// 列表数据源
	const queryList = async init => {
		tableData.loading = true;
		let res = await standardMaintainListApi(queryParams);
		if (res.data.code !== 200) return;
		tableData.data = res.data.data.list || [];
		tableData.total = res.data.data.total || 0;
		tableData.loading = false;
	};

	// 分页
	const pageChange = (type, size) => {
		if (type == 'size') {
			queryParams.pageSize = size;
		} else {
			queryParams.pageNumber = size;
		}
		queryList();
	};

	queryList();
</script>
